package com.ruoyi.comparison.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.comparison.domain.bo.TaskResultBo;
import com.ruoyi.comparison.domain.vo.TaskResultVo;
import com.ruoyi.comparison.service.ITaskResultService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比对结果
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/result")
public class TaskResultController extends BaseController {

    private final ITaskResultService iTaskResultService;

    /**
     * 查询比对结果列表
     */
    @SaCheckPermission("system:oss:list")
    @GetMapping("/list")
    public TableDataInfo<TaskResultVo> list(TaskResultBo bo, PageQuery pageQuery) {
        return iTaskResultService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出比对结果列表
     */
    @SaCheckPermission("system:oss:list")
    @Log(title = "比对结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TaskResultBo bo, HttpServletResponse response) {
        List<TaskResultVo> list = iTaskResultService.queryList(bo);
        ExcelUtil.exportExcel(list, "比对结果", TaskResultVo.class, response);
    }

    /**
     * 新增比对结果
     */
    @SaCheckPermission("system:oss:list")
    @Log(title = "比对结果", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TaskResultBo bo) {
        return toAjax(iTaskResultService.insertByBo(bo));
    }

    /**
     * 修改比对结果
     */
    @SaCheckPermission("system:oss:list")
    @Log(title = "比对结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TaskResultBo bo) {
        return toAjax(iTaskResultService.updateByBo(bo));
    }

    /**
     * 删除比对结果
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:oss:list")
    @Log(title = "比对结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTaskResultService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
